package com.apexwear.apexutils.data;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.callback.WeatherCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.QueryWatchInfoType;
import com.apex.bluetooth.model.EABleWeather;

public class WeatherData extends ViewModel {
    public MutableLiveData<EABleWeather> getWeather() {
        MutableLiveData<EABleWeather> mutableLiveData = new MutableLiveData<>();
        EABleManager.getInstance().queryWatchInfo(QueryWatchInfoType.weather, new WeatherCallback() {
            @Override
            public void weatherInfo(EABleWeather eaBleWeather) {
                mutableLiveData.postValue(eaBleWeather);
            }

            @Override
            public void mutualFail(int i) {
                mutableLiveData.postValue(null);
            }
        });
        return mutableLiveData;
    }

    public MutableLiveData<Boolean> setWeather(EABleWeather eaBleWeather) {
        MutableLiveData<Boolean> mutableLiveData = new MutableLiveData<>();
        EABleManager.getInstance().setWeather(eaBleWeather, new GeneralCallback() {
            @Override
            public void result(boolean b,int i) {
                mutableLiveData.postValue(b);
            }

            @Override
            public void mutualFail(int i) {
                mutableLiveData.postValue(false);
            }
        });
        return mutableLiveData;
    }
}
